package com.example.orderservice.event;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单事件基类
 * 用于在微服务间传递订单状态变更信息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public abstract class OrderEvent {
    
    private String eventId;
    private String orderId;
    private LocalDateTime timestamp;
    private String eventType;
    
    public OrderEvent(String orderId, String eventType) {
        this.eventId = java.util.UUID.randomUUID().toString();
        this.orderId = orderId;
        this.eventType = eventType;
        this.timestamp = LocalDateTime.now();
    }
}

/**
 * 订单创建事件
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderCreatedEvent extends OrderEvent {
    
    private String customerId;
    private List<OrderItem> items;
    private Double totalAmount;
    
    public OrderCreatedEvent(String orderId, String customerId, List<OrderItem> items, Double totalAmount) {
        super(orderId, "ORDER_CREATED");
        this.customerId = customerId;
        this.items = items;
        this.totalAmount = totalAmount;
    }
}

/**
 * 订单支付事件
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderPaidEvent extends OrderEvent {
    
    private String paymentId;
    private String paymentMethod;
    private Double amount;
    
    public OrderPaidEvent(String orderId, String paymentId, String paymentMethod, Double amount) {
        super(orderId, "ORDER_PAID");
        this.paymentId = paymentId;
        this.paymentMethod = paymentMethod;
        this.amount = amount;
    }
}

/**
 * 订单取消事件
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderCancelledEvent extends OrderEvent {
    
    private String reason;
    
    public OrderCancelledEvent(String orderId, String reason) {
        super(orderId, "ORDER_CANCELLED");
        this.reason = reason;
    }
}

/**
 * 订单项
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderItem {
    private String productId;
    private String productName;
    private Integer quantity;
    private Double unitPrice;
}
